
<input name="_csrf" type="hidden" id="_csrf" value="<{$app->request->csrfToken}>">
    <div class="content margin_top_foot">
        <div class="searchbar fixed_top bg_mx_green white"></div>
        <div class="refresh_content">
            <div class="pull_refresh">
                <div class="font_16 margin_b_15 bg_white lineheight_4 text_center flex title_nav">
                    <div class="flex_1 <{if $by == 'price' || is_null($by)}>active_border<{/if}>">
                    <a href="<{url route='/shop/goods/list' cid=$cid by='price'}>">价格</a></div>
                    <div class="flex_1 <{if $by == 'num'}>active_border<{/if}>"><a href="<{url route='/shop/goods/list' cid=$cid by='num'}>">销量</a></div>
                    <div class="flex_1 <{if $by == 'comment'}>active_border<{/if}>"><a href="<{url route='/shop/goods/list' cid=$cid by='comment'}>">评价</a></div>
                </div>
                <div class="flex_row_2 padding_h_15 pros"></div>
            </div>
            <div class="refresh_load"><div class="refresh_pull_arrow"></div></div>
        </div>
        <div class="sidebar fixed lineheight_4 white hide"></div>
        <div class="sidecon row padding_h_15 fixed lineheight_4 bg_white hide mx_green text_center"></div>
        <footer class="foot_tab fixed_bottom mx_green font_16"></footer>
    </div>
    <div class="toast"></div>
    <!-- toast模版 -->
    <script type="text/template" charset="utf-8" id='toast_template'>
        <i class="iconfont icon-toast{{=it.icon}}"></i>
        <div class="toast_text">{{=it.text}}</div>
    </script>
    <!-- 侧边栏模版 -->
    <script type="text/template" charset="utf-8" id='nav_template'>
        {{for(var i=0;i<it.length;i++){}}
        <div class="border_b padding_l_15" data-n="{{=i}}">{{=it[i].name}}</div>
        {{}}}
    </script>
    <script type="text/template" charset="utf-8" id='navcon_template'>
        {{if(it.length){}}
            {{for(var i=0;i<it.length;i++){}}
            <div class="col_4" onclick="location.href='{{=it[i].url}}'">{{=it[i].name}}</div>
            {{}}}
        {{}else{}}
            <div>暂无数据</div>
        {{}}}
    </script>
    <script type="text/template" charset="utf-8" id='pro_template'  ></script>
    <script>

        // 页面初始化
        //     var mycarts = get_data("cart")||{};

            var mycarts = get_data("cart")||{total:0};
            var len = mycarts.total;
            loadsearchbar(function(){
                if(len){
                    $(".total").html(len);
                }else{
                    $(".total").hide();
                }
            });
            var pros = <{$goods}>,evalpros;
            loadpro(pros)
            loadfootbar();
        // 侧边栏
            var navs = <{$cate}>;console.log(navs)
            var evalnav = doT.template($("#nav_template").text());
            var evalnavcon = doT.template($("#navcon_template").text());
            var navs = <{$cate}>;console.log(navs)
            loaddata(".sidebar",evalnav,navs)
            if(!navs[0].hasOwnProperty('items')){
                navs[0].items = []
            }
            loaddata(".sidecon",evalnavcon,navs[0].items)
            $(".sidebar .border_b:first-child").addClass("mx_green")
            $(".searchbar").on("click",".searchbar_icon.icon-menu",function(){
                $(".sidecon").slideToggle()
            })
            $(".sidebar").on("click",".border_b",function(){
                $(this).addClass("mx_green").siblings().removeClass("mx_green")
                loaddata(".sidecon",evalnavcon,navs[$(this).data("n")].items||[])
            })
        // 搜索
            var evalToast = doT.template($("#toast_template").text());
            $(".content").on("input",".searchbar_input input",function(){
                var that = this;
                var keywords = $(this).val();
                if(keywords){
                    $.post("/shop/site/search-goods",{keywords:keywords,_csrf:$('#_csrf').val()},function(res){
                        if(res.status && res.status == 1){
                            toast("attention",res.msg)
                        }else{
                            $(".pros").html(evalpros(res))
                        }
                     },"json")
                }
            })
            function search(obj){
                var keywords = $(obj).next().val();
                if(keywords){
                    $.post("/shop/site/search-goods",{keywords:keywords,_csrf:$('#_csrf').val()},function(res){
                        if(res.status && res.status == 1){
                            toast("attention",res.msg)
                        }else{
                            $(".pros").html(evalpros(res))
                        }
                    },"json")
                }else{
                    toast("attention","请输入搜索关键词",function(){
                        $(obj).next().focus()
                    });
                }
            }
        // 下拉加载更多
            var pindex = 1;
            var pullRefresh = new mobileRefresh({
                container: document.querySelector('.refresh_content'),
                triggerDistance: 100,
                type:"up"
            },function(){
                $.post("/shop/goods/load-more",{cid:<{$app->request->get('cid')}>,pindex:++pindex,_csrf:$('#_csrf').val()},function(res){
                    $(".pros").append(evalpros(res));
                    pullRefresh.cancelLoading();
                },"json")
            })
        // 购物车操作
        function cart(i){
            if(pros[i].nums <= 0){
                toast("attention","该产品已售罄");
                return false;
            }
            mycarts = get_data("cart")||{total:0};
            console.log(pros[i]);
            if(!$.isEmptyObject(mycarts[pros[i].id]) && mycarts[pros[i].id].num >= pros[i].nums){
                return false;
            }

            addcart(1,pros[i])
        }
    </script>


